package com.zjt.service.product;

import com.zjt.dao.product.ISecurityCodeDao;
import com.zjt.entity.product.SecurityCode;
import com.zjt.utils.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created with IntelliJ IDEA.
 * User: xueyanbeijing
 * Date: 12-8-29
 * Time: AM9:39
 * 厂家接口防伪方式接口实现
 * To change this template use File | Settings | File Templates.
 */
@Component
public class SecurityCodeService implements ISecurityCodeService{
    private ISecurityCodeDao securityCodeDao;
    private static Logger logger = LoggerFactory.getLogger(SecurityCodeService.class);
    @Autowired
    public void setSecurityCodeDao(ISecurityCodeDao securityCodeDao) {
        this.securityCodeDao = securityCodeDao;
    }

    @Override
    public SecurityCode saveSecurityCode(long userId, long productId, String barCode, String securityCode) {
        SecurityCode securityCode1 = new SecurityCode();
        try
        {
            securityCode1.setBarCode(barCode);
            securityCode1.setProductId(productId);
            securityCode1.setSecurityCode(securityCode);
            securityCode1.setUserId(userId);
            securityCode1.setCreateDate(DateUtil.getCurrentDate());
            securityCode1.setUpdateDate(DateUtil.getCurrentDate());
            securityCode1.setEnableFlag("A");
            securityCode1 = this.securityCodeDao.save(securityCode1) ;
        }catch (Exception e){
            logger.error("保存防伪码异常"+securityCode1.toString());
        }
        return securityCode1;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public SecurityCode getSecurityCodeByProductId(long userId, long productId) {
        return this.securityCodeDao.findByUserIdAndProductId(userId,productId);  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public SecurityCode getSecurityCodeByBarCode(long userId, String barCode) {
        return this.securityCodeDao.findByUserIdAndBarCode(userId,barCode);  //To change body of implemented methods use File | Settings | File Templates.
    }
}
